//
//  OADSturctViewController.m
//  OASDK_Works
//
//  Created by ChenJie on 4/20/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "OADSturctViewController.h"

typedef struct Node {
    CGFloat left;
    CGFloat top;
    CGFloat width;
    CGFloat height;
    
//    struct Node subnodes[100];
//    CGFloat floats[100];
//    struct Node * nodes[100];
//    struct Node * nextNode;
//    struct Node *subnodes[10];
    
    struct Node *nextNode;
    struct Node *nodes[10];
} Node;

#define kObj &(Node)

@interface OADSturctViewController ()

//@property (nonatomic, assign) Node node1;
//@property (nonatomic, strong) NSValue *value1;

@end

@implementation OADSturctViewController

#pragma mark - ViewController lifecycle

- (instancetype)init {
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = NSStringFromClass(self.class);
    
    //
    
    Node node1 = (Node){
        .left = 10,
        .top = 20,
        .width = 30,
        .height = 40,
        .nextNode = &(Node){
            .left = 101,
            .top = 201,
            .width = 301,
            .height = 401,
        },
        .nodes = {
            &(Node){
                .left = 110,
                .top = 120,
                .width = 130,
                .height = 140,
            }
        },
        
//        .subnodes = {
//            &(Node){
//                .left = 110,
//                .top = 120,
//                .width = 130,
//                .height = 140,
//            },
//            &(Node){
//                .left = 1102,
//                .top = 1202,
//                .width = 1302,
//                .height = 1402,
//            },
//        },
        
//        .nodes = {
//            &(Node){
//                .left = 101,
//                .top = 201,
//                .width = 301,
//                .height = 401,
//            },
//            &(Node){
//                .left = 102,
//                .top = 202,
//                .width = 302,
//                .height = 402,
//            },
//        },
    };
    
//    NSLog(@"left: %f", node1.left);
//    NSLog(@"l: %@", n1.subnodes);
    
    NSValue *value1 = [self valueWithNode:node1];
    Node node11 = [self nodeValue:value1];
    
    NSLog(@"node1 left is: %f", node11.nextNode->left);
    NSLog(@"node1 top is: %f", node11.nextNode->top);
    NSLog(@"node1 width is: %f", node11.nextNode->width);
    NSLog(@"node1 height is: %f", node11.nextNode->height);
    
    
    int size = sizeof(node11.nodes) / sizeof(node11.nodes[0]);
    NSLog(@"size is: %d", size);
    
//    Node *node111 = node11.subnodes[1];
//    NSLog(@"node1 left is: %f", node111->left);
//    NSLog(@"node1 top is: %f", node111->top);
//    NSLog(@"node1 width is: %f", node111->width);
//    NSLog(@"node1 height is: %f", node111->height);
    
    
    
    
//    struct Node * subnodes[10] = node11.subnodes;
    
//    NSInteger length = node11.subnodes.length;
}


- (NSValue *)valueWithNode:(Node)node {
    return [NSValue valueWithBytes:&node objCType:@encode(Node)];
}

- (Node)nodeValue:(NSValue *)value {
    Node node;
    [value getValue:&node];
    return node;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    //
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - Public methods



#pragma mark - Private methods



#pragma mark - Event response methods

- (void)buttonClicked:(UIButton *)button {
    NSLog(@"button clicked...");
}

#pragma mark - Deletate methods



#pragma mark - Setter



#pragma mark - Getter



#pragma mark - Memory management

- (void)dealloc {
}

@end
